#include "Lever.h"

CLever::CLever(void)
{
}

CLever::~CLever(void)
{
}

void CLever::Init(int worldX, int worldY, CPlayer *playerPtr, Tiles *tilesPtr)
{
	pickedUp = false;
	x = worldX * 32;
	y = worldY * 32 + 10;
	
	height = 22;
	width = 34;
	tiles = tilesPtr;

	images = new HANDLE[1];
	char picfile[] = "res/leverunturned.bmp";
	images[0] = LoadImage(NULL, picfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
	char picfile1[] = "res/leverturned.bmp";
	images[1] = LoadImage(NULL, picfile1, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

	player = playerPtr;

}

void CLever::Draw(HDC graphics)
{
	if(!pickedUp)
		RenderHelper::RenderBitmap(graphics, images[0], x,y, width, height);
	else
		RenderHelper::RenderBitmap(graphics, images[1], x,y, width, height);

}

void CLever::Update()
{
	if(!pickedUp)
	{
		int DifX = (((int)player->x) - ((int)x));
		int DifY = (((int)player->y) - ((int)y));

		//if the player is at the same location=>dies
		if(DifX <= 30 && DifX >= -30 && DifY <= 30 && DifY >= -30)
		{
			if(!pickedUp)
			{
				CSoundPlayer::PlaySound1("music\\door-open-1.wav");
				tiles->tiles[10][68] = -1;
				tiles->tiles[11][68] = -1;
				pickedUp = true;
			}
		}
	}
}
